package com.bag;

import static java.lang.Math.max;

public class dome01 {
    int N = 1000;
    //单个物品的重量和价值
    int[] w = new int[]{0,2,2,6,5,4};
    int[] v = new int[]{0,6,3,5,4,6};
    //dp[i][j]表示前i件物品放到背包容量为j的最大价值
    int [][] dp = new int[N][N];

    public void solution() {
        int n = 5;//物品的数量
        int c = 10;//背包的容量
        for(int i = 1; i <= n; i++)
        {
            for(int j = c; j >= 0; j--)
            {
                //如果当前放得下
                if(w[i] <= j)
                    dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
                else
                    dp[i][j] = dp[i-1][j];
            }
        }
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=c;j++)
            {
                System.out.printf("%4d",dp[i][j]);
            }
            System.out.println();
        }
        System.out.println(dp[n][c]);
    }
}
